home *** CD-ROM | disk | FTP | other *** search
- /* ---------------------------------------------------------------------------------------------
- Find_icon, code for constructing icon suites for files and folders
-
- by James W. Walker
- preferred e-mail: <mailto:jwwalker@kagi.com>
- alternate e-mail: <mailto:jwwalker@aol.com>, <jim@nisus-soft.com>
- web: <http://users.aol.com/jwwalker/>
-
- File: Get_normal_folder_icon.c
-
- Copyright ©1997 by James W. Walker
-
- You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided "AS IS" and the
- responsibility for its operation is 100% yours.
- If you're going to re-distribute the source, please make it clear
- that the code was descended from James W. Walker's code,
- but that you've made changes.
- ---------------------------------------------------------------------------------------------
- */
-
- #include <Icons.h>
- #include <Finder.h>
- #include <Folders.h>
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
- #include "Get_normal_folder_icon.h"
- #include "Get_resource_icons.h"
- #include "Copy_each_icon.h"
- #include "Find_icon.h"
-
-
- typedef struct {OSType folder_type; long icon_id;} FolderPair;
-
- static const FolderPair sFolderIconPair[] =
- {
- { kExtensionFolderType, kExtensionsFolderIconResource },
- //{ kSystemFolderType, kSystemFolderIconResource }, // special-cased
- { kControlPanelFolderType, kControlPanelFolderIconResource },
- { kFontsFolderType, kFontsFolderIconResource },
- { kPreferencesFolderType, kPreferencesFolderIconResource },
- { kAppleMenuFolderType, kAppleMenuFolderIconResource },
- { kPrintMonitorDocsFolderType, kPrintMonitorFolderIconResource },
- //{ kTrashFolderType, kTrashIconResource }, // trash is special, can be on any volume
- { kStartupFolderType, kStartupFolderIconResource },
- { kShutdownFolderType, kStartupFolderIconResource }
- };
-
- /* ------------------------------------------------------------------
- Get_normal_folder_icon Create an icon suite for a folder
- that does not have a custom icon.
- ------------------------------------------------------------------
- */
- OSErr Get_normal_folder_icon(
- /* --> */ const CInfoPBRec *cpb,
- /* --> */ MetaSelectorValue icon_selector,
- /* <-- */ Handle *the_suite
- )
- {
- OSErr err;
- short sys_vRefNum, trash_vRefNum, icon_id;
- long sys_dirID, trash_dirID, dirID;
- short save_resfile;
- short index;
- short found_vRefNum;
- long found_dirID;
- IconSelectorValue second_selector;
- short pairCount;
-
- ExpandMetaSelector( icon_selector, &icon_selector, &second_selector );
-
- dirID = cpb->dirInfo.ioDrDirID;
-
- if ( (FindFolder( cpb->dirInfo.ioVRefNum, kSystemFolderType, kDontCreateFolder,
- &sys_vRefNum, &sys_dirID ) == noErr)
- && (sys_vRefNum == cpb->dirInfo.ioVRefNum)
- && (sys_dirID == dirID) )
- {
- icon_id = kSystemFolderIconResource;
- }
- else if ( (FindFolder( cpb->dirInfo.ioVRefNum, kTrashFolderType, kDontCreateFolder,
- &trash_vRefNum, &trash_dirID ) == noErr)
- && (trash_vRefNum == cpb->dirInfo.ioVRefNum)
- && (trash_dirID == dirID) )
- {
- icon_id = kTrashIconResource;
- }
- else if ( (sys_vRefNum == cpb->dirInfo.ioVRefNum) &&
- (sys_dirID == cpb->dirInfo.ioDrParID) )
- {
- /*
- The folder is a subfolder of the System Folder, so it
- might be one with a special icon.
- */
- icon_id = kGenericFolderIconResource; // default
- pairCount = sizeof(sFolderIconPair) / sizeof(FolderPair);
-
- for (index = 0; index < pairCount; ++index)
- {
- err = FindFolder( sys_vRefNum,
- sFolderIconPair[index].folder_type,
- kDontCreateFolder, &found_vRefNum, &found_dirID );
- if ( (err == noErr) && (found_dirID == dirID) )
- {
- icon_id = sFolderIconPair[index].icon_id;
- break;
- }
- }
- }
- else
- {
- /* These attribute bits are described in TN 301. */
- if ((cpb->dirInfo.ioFlAttrib & 0x08) != 0)
- icon_id = kMountedFolderIconResource;
- else if ((cpb->dirInfo.ioFlAttrib & 0x20) != 0)
- icon_id = kSharedFolderIconResource;
- else if ((cpb->dirInfo.ioFlAttrib & 0x04) != 0)
- icon_id = kOwnedFolderIconResource;
- else
- icon_id = kGenericFolderIconResource;
- }
-
- save_resfile = CurResFile();
- UseResFile(0); // look in the System file
- // The reason I use Get_resource_icons instead of Get1_resource_icons
- // here is for compatibility with Aaron.
- err = Get_resource_icons( the_suite, icon_id, icon_selector );
- if ( (*the_suite == NULL) && (second_selector != 0) )
- {
- err = Get_resource_icons( the_suite, icon_id, second_selector );
- }
-
- UseResFile( save_resfile );
-
- return err;
- }
-